/*
 * ========================================================================
 *
 *       Filename:  app.cpp
 *
 *    Description:  This implements and runs the flashcard program.
 *
 *        Version:  0.3
 *        Created:  05/11/2010 09:00:50 AM
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  Alex Avance (aa), aravance@gmail.com
 *        Company:  independent
 *
 * ========================================================================
 *
 * Copyright (C) 2010 Alex Avance
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 * ========================================================================
 */
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif // __BORLANDC__

#include <ctime>
#include <cstdlib>
#include "wx/app.h"
#include "wx/cmdline.h"
#include "app.h"
#include "fcframe.h"
#include "constants.h"

IMPLEMENT_APP( FlashCardApp );

bool FlashCardApp::OnInit ()
{
  FlashCardFrame *frame= new FlashCardFrame( _("FlashCard"), wxDefaultPosition, DEFAULT_SIZE );
  wxCmdLineParser parser( argc, argv );

  static const wxCmdLineEntryDesc cmdLineDesc[]=
  {
    { wxCMD_LINE_SWITCH, _("h"), _("help"), _("print this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
    { wxCMD_LINE_SWITCH, _("V"), _("version"), _("print version information"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
    { wxCMD_LINE_PARAM, _(""), _(""), _("file(s)"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
    { wxCMD_LINE_NONE }
  };

  parser.SetDesc( cmdLineDesc );

  if ( parser.Parse() != 0 )
    return false;

  if ( parser.Found( _("V") ) )
  {
    wxPrintf( _("flashcard v"VERSION_STRING"\n"
                COPYRIGHT_STRING"\n"
                DESCRIPTION_STRING"\n") );
    return false;
  }

  for ( size_t i= 0; i < parser.GetParamCount(); ++i )
    frame->Open( parser.GetParam( i ) );

  srand( time( NULL ) );

  frame->Layout();
  frame->SetMinSize( MIN_SIZE );
  frame->Show( true );
  SetTopWindow( frame );

  return true;
}

